#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time : 2023/7/7 9:46
# @Author : 搬砖客
# @File : get_jenkins_job.py
# @Software: PyCharm


import requests

from utils.process_files_utils.yaml_util import YamlUtil


def get_allure_url():
    jenkins_url = "http://" + str(YamlUtil.read_config_yaml("host", "jenkins_host")) + ":" + str(
        YamlUtil.read_config_yaml("port", "jenkins_port"))
    job_name = str(YamlUtil.read_config_yaml("project", "name"))
    api_url = f"{jenkins_url}/job/{job_name}/lastBuild/api/json"
    response = requests.get(api_url)
    response_json = response.json()
    # Extract the build ID from the JSON response
    build_id = response_json["id"]
    allure_url = f"{jenkins_url}/job/{job_name}/{build_id}/allure/"
    return allure_url
